<?php

if (!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
    exit('Access Denied');
}
global $_G;
include DISCUZ_ROOT . './source/plugin/qu_app/ainuo.php';
loadcache('plugin');
$dirname = DISCUZ_ROOT . '/data/sysdata/qu_app_cache';
$dirnamepic = DISCUZ_ROOT . '/data/attachment/qu_app';
cpheader();
if ($operation == 'config') {
    $step = max(1, intval($_GET['step']));
    shownav('tools', 'nav_updatecache');
    showsubmenusteps('nav_updatecache', array(0 => array(0 => 'nav_updatecache_confirm', 1 => $step == 1), 1 => array(0 => 'nav_updatecache_verify', 1 => $step == 2), 2 => array(0 => 'nav_updatecache_completed', 1 => $step == 3)));
    if ($step == 1) {
        cpmsg('', 'action=plugins&operation=config&do=' . $pluginid . '&identifier=qu_app&pmod=cache&step=2', 'form', '', false);
    } else {
        if ($step == 2) {
            $type = implode('_', (array) $_GET['type']);
            cpmsg(cplang('tools_updatecache_waiting'), 'action=plugins&operation=config&do=' . $pluginid . '&identifier=qu_app&pmod=cache&step=3&type=$type', 'loading', '', false);
        } else {
            if ($step == 3) {
                $type = explode('_', $_GET['type']);
                rmdirr($dirname);
                rmdirr($dirnamepic);
                cpmsg('update_cache_succeed', '', 'succeed', '', false);
            }
        }
    }
}
$finish = true;
function rmdirr($dirname)
{
    if (!file_exists($dirname)) {
        return false;
    }
    if (!is_file($dirname)) {
        if (is_link($dirname)) {
            return unlink($dirname);
        }
    }
    $dir = dir($dirname);
    $entry = $dir->read();
    while (false !== $entry) {
        if ($entry != '.') {
            if ($entry == '..') {
                continue;
            }
        }
        rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
    }
    $dir->close();
    return rmdir($dirname);
}